package test_money;

import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-11-26
 * Time:10:07
 */
public class TestDemo {
    public  static int moneyCount(int[][] moneycount,int money){
        int count = 0;
        for (int i = moneycount.length - 1; i >= 0 ; i--) {
            int c = Math.min(money/moneycount[i][0],moneycount[i][1]);
            money = money - c*moneycount[i][0];
            count += c;
        }
        if (money != 0){
            return  -1;
        }
        return  count;
    }
    public static void main(String[] args) {
        int[][] moneycount = { { 1, 3 }, { 2, 1 }, { 5, 4 }, { 10, 3 }, { 20, 0 }
                ,{50, 1}, { 100, 10 } };
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要多少钱");
        int money = scanner.nextInt();

        int ret = moneyCount(moneycount,money);
        System.out.println(ret);
    }
}
